﻿using models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DAL;
using System.Data.SqlClient;


namespace BLL
{
    public class UserMarager
    {
        userService service = new userService();
        //用户新增操作
        public bool AddUser(User user)
        {
            return service.Adduser(user);
        }
        //修改用户个人信息
        public bool updataUsers(User user ,string id)
        {
            return service.updataUser(user ,id);
        }
        //修改用户登录密码
        public bool updatapasswords(User user)
        {
            return service.updatapassword(user);
        }
        //修改用户手机验证
        public bool updataphones(User user)
        {
            return service.updataphone(user);
        }
        //修改用户邮箱验证
        public bool updataemails(User user)
        {
            return service.updataemail(user);
        }
        //查询用户信息
        public List<User> GetUser()
        {
            List<User> users = new List<User>();
            SqlDataReader reader = service.selectUser();
            while (reader.Read())
            {
                users.Add(
                    new User(
                        reader.GetInt32(0),
                        reader.GetString(1),
                        reader.GetString(2),
                        reader.GetString(3),
                        reader.GetString(4),
                        reader.GetString(5),
                        reader.GetDecimal(6),
                        reader.GetString(7)
                        ));
            }
            DBhelper.Close();
            return users;
        }

        //根据id查询用户
        public List<User> GetUserid(int id)
        {
            List<User> users = new List<User>();
            SqlDataReader reader = service.selectUserid(id);
            while (reader.Read())
            {
                users.Add(
                    new User(
                        reader.GetInt32(0),
                        reader.GetString(1),
                        reader.GetString(2),
                        reader.GetString(3),
                        reader.GetString(4),
                        reader.GetString(5),
                        reader.GetDecimal(6),
                        reader.GetString(7)
                        ));
            }
            DBhelper.Close();
            return users;
        }
        //用户登录
        public List<User> dl(string uid, string pwd)
        {
            List<User> users = new List<User>();
            SqlDataReader reader = service.dl(uid, pwd);
            User user = null;
            if (reader.Read())
            {
                user = new User(
                    reader.GetInt32(0),
                    reader.GetString(1),
                    reader.GetString(2),
                    reader.GetString(3),
                    reader.GetString(4),
                    reader.GetString(5),
                    reader.GetDecimal(6),
                    reader.GetString(7)
                    );
                users.Add(user);
            }
            DBhelper.Close();
            return users;
        }
        public User dlbyphone(decimal phone, string pwd)
        {
            SqlDataReader reader = service.dhdl(phone, pwd);
            User user = null;
            if (reader.Read())
            {
                user = new User(
                    reader.GetInt32(0),
                    reader.GetString(1),
                    reader.GetString(2),
                    reader.GetString(3),
                    reader.GetString(4),
                    reader.GetString(5),
                    reader.GetDecimal(6),
                    reader.GetString(7)
                    );
            }
            DBhelper.Close();
            return user;
        }
        //登录判定
        public User Getdl(string uid, string pwd)
        {

            SqlDataReader reader = service.dl(uid, pwd);
            User user = null;
            if (reader.Read())
            {
                user = new User(
                    reader.GetInt32(0),
                    reader.GetString(1),
                    reader.GetString(2),
                    reader.GetString(3),
                    reader.GetString(4),
                    reader.GetString(5),
                    reader.GetDecimal(6),
                    reader.GetString(7)
                    );

            }
            DBhelper.Close();
            return user;

        }
    }

}
